<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            var maxSubArray = function (nums) {
                let dp = new Array(nums.length).fill(0)
                let result = 0
                dp[0] = nums[0]
                for (let i = 1; i < nums.length; i++) {
                    dp[i] = Math.max(dp[i - 1] + nums[i], nums[i])
                    result = Math.max(result, dp[i])
                }
                return result
            }
            maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4])
        </script>
    </body>
</html>
